package com.learning.jquizenglish.screen.flashcard;

import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.learning.jquizenglish.R;
import com.learning.jquizenglish.common.controller.JQuizSettings;
import com.learning.jquizenglish.common.fragment.JQuizEnglishFragment;
import com.learning.jquizenglish.common.preference.SettingsPrefference;
import com.learning.jquizenglish.model.AnswerModel;
import com.learning.jquizenglish.model.CardItemModel;
import com.learning.jquizenglish.model.QuestionModel;

public class CardFragment extends JQuizEnglishFragment {

	private int cardIndex;
	private TextView tvTerm;
	private TextView tvDefinition;
	
	@Override
	protected View onCreateContentView(LayoutInflater inflater,
			ViewGroup container) {
		View v = LayoutInflater.from(getActivity()).inflate(R.layout.card_page, container,false);
		tvTerm = (TextView) v.findViewById(R.id.tvTerm);
		tvDefinition = (TextView) v.findViewById(R.id.tvDefinition);
		cardIndex = getArguments().getInt("page", 0);
		setUpData();
		return v;
	}
	
	private void setUpData(){
		final CardItemModel model = FlashCardStore.getInstance().getListCard().get(cardIndex);
		JQuizSettings.setFlashCardFontSize(getActivity(), tvTerm);
		JQuizSettings.setFlashCardFontSize(getActivity(), tvDefinition);
		boolean isShowTerm = SettingsPrefference.getInstance().isFlashCardShowTerm();
		boolean isShowDefinition = SettingsPrefference.getInstance().isFlashCardShowDefinition();
		if (!isShowTerm) {
			tvTerm.setText("");
			tvTerm.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					tvTerm.setText(model.term);
					tvTerm.setOnClickListener(null);
				}
			});
		}else{
			tvTerm.setText(model.term);
		}
		if (!isShowDefinition) {
			tvDefinition.setText("");
			tvDefinition.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					tvDefinition.setText(model.definition);
					tvDefinition.setOnClickListener(null);
				}
			});
		}else{
			tvDefinition.setText(model.definition);
		}
	}
	
	public static CardFragment createCard(int pos){
		CardFragment cardFrag = new CardFragment();
		Bundle bundle = new Bundle();
		bundle.putInt("page", pos);
		cardFrag.setArguments(bundle);
		return cardFrag;
	}

}
